class_name InputActionChecker
## Input Action Checker
## Version: 0.1.0

##
var action_name: String = ""

##
var is_double_click_started := false

##
var is_pressed := false

##
var is_long_pressed := false

##
var is_released := false

##
var _double_click_threshold := 0.2

##
var _long_pressed_threshold := 0.2

##
var _last_press_start_time := 0.0


func _ready() -> void:
	assert(action_name != "", "Action name must be set!")


func on_update(_delta: float) -> void:
	var current_time := Time.get_ticks_msec() / 1000.0

	if Input.is_action_just_pressed(action_name):
		if current_time - _last_press_start_time < _double_click_threshold:
			is_double_click_started = true
		_last_press_start_time = current_time
	
	if Input.is_action_pressed(action_name):
		is_pressed = true
		if current_time - _last_press_start_time > _long_pressed_threshold:
			is_long_pressed = true

	if Input.is_action_just_released(action_name):
		is_released = true
		is_pressed = false
		is_long_pressed = false
		is_double_click_started = false
	else:
		is_released = false
